﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

using eTraining.PageProcess;

namespace eTraining
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Resize(object sender, EventArgs e)
        {
            
            StyleHelper.SetWindowsRegion(this);
        }

        private void MainForm_MouseMove(object sender, MouseEventArgs e)
        {
            int mode = StyleHelper.HitTestFormBorder(e.Location,this);
            Cursor = StyleHelper.GetCursorForMode(mode);
           
            
        }

        
        private void MainForm_MouseLeave(object sender, EventArgs e)
        {
            Cursor = Cursors.Default;
        }


        private void Title_DoubleClick(object sender, EventArgs e)
        {

        }

        private void MainForm_Enter(object sender, EventArgs e)
        {
           
        }

        private void MainForm_ResizeEnd(object sender, EventArgs e)
        {
        }

        private void Title_Load(object sender, EventArgs e)
        {

        }

        public void UpdateUserInfo()
        {
            frmUser frm = new frmUser();
            frm.ShowDialog();
        }

        private Dictionary<string, PageProcessBase> _PageProcess = new Dictionary<string, PageProcessBase>();

        internal Dictionary<string, PageProcessBase> PageProcess
        {
            get 
            {
                if (_PageProcess.Count == 0)
                {
                    Assembly assem = this.GetType().Assembly;
                    foreach (Type typ in assem.GetTypes())
                    {
                        if (typ.IsSubclassOf(typeof(PageProcessBase)) == true)
                        {
                            PageProcessBase ppb = assem.CreateInstance(typ.FullName) as PageProcessBase;
                            _PageProcess.Add(ppb.URI.ToString(), ppb);
                        }
                    }
                }
                return _PageProcess; 
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            Show();
            Refresh();

            string path = Application.StartupPath;
            path += @"../../../html/index.HTML";

            WB.WebBrowserShortcutsEnabled = false;
            WB.Url = new Uri(System.IO.Path.GetFullPath(path));

            WB.IsWebBrowserContextMenuEnabled = false;
            WB.WebBrowserShortcutsEnabled = false;
        }

        private void WB_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            
            
            if (PageProcess.ContainsKey(e.Url.ToString()) == true)
            {
                PageProcess[e.Url.ToString()].DocumentCompletedProcess(sender as WebBrowser, e);
            }
            //Console.WriteLine(e.Url.ToString());
        }
    }
}
